# coding:utf-8
import pymysql
from pymysql.converters import escape_string
import time

conn = pymysql.connect(host="127.0.0.1", port=3306, user="root", password="root", db="test", charset="utf8")


def select_all(table_name):
    cursor = conn.cursor()
    count = cursor.execute("select * from %s" % table_name)
    cursor.close()
    return cursor.fetchall()

def select_where(table_name, w, e):
    cursor = conn.cursor()
    count = cursor.execute("select mobile_no from %s where %s=%s " % (table_name, w, e))
    cursor.close()
    # if count > 0:
    #     pass
    # else:
    #     print(e)
    return cursor.fetchall()


def insert_one(contacts, phone, mobile_no, key_word, company_name, company_nameCN, source, alibabaId, is_overseas,
               account_job, account_jobCN, account_fax, qq, wechart, wechart_remarks, is_wechart, category, industry,
               company_address, account_country, products, company_url, account_province, account_city,
               association_number, pullnew_uid, pullnew_name, conversion_uid, conversion_name, exchange_id, status,
               is_connect, keyword_id, is_handle, create_time, update_time, businessscope,
               customer_status, register_id, remark, version):
    cursor = conn.cursor()
    count = cursor.execute(
        "insert  into 1688_all_spider(id,contacts,phone,mobile_no,key_word,company_name,company_nameCN,source,alibabaId,is_overseas,account_job,account_jobCN,account_fax,qq,wechart,wechart_remarks,is_wechart,category,industry,company_address,account_country,products,company_url,account_province,account_city,association_number,pullnew_uid,pullnew_name,conversion_uid,conversion_name,exchange_id,status,is_connect,keyword_id,is_handle,create_time,update_time,receive_time,end_time,businessscope,customer_status,register_id,remark,version) value (NULL,'%s','%s','%s','%s','%s','%s',%d,'%s',%d,'%s','%s','%s','%s','%s','%s',%d,'%s','%s','%s','%s','%s','%s','%s','%s','%s',%d,'%s',%d,'%s',%d,%d,%d,%d,%d,'%s','%s',NULL ,NULL,'%s',%d,%d,'%s',%d)" % (
            contacts, phone, mobile_no, key_word, company_name, company_nameCN, source, alibabaId, is_overseas,
            account_job, account_jobCN, account_fax, qq, wechart, wechart_remarks, is_wechart, category, industry,
            company_address, account_country, products, company_url, account_province, account_city,
            association_number, pullnew_uid, pullnew_name, conversion_uid, conversion_name, exchange_id, status,
            is_connect, keyword_id, is_handle, create_time, update_time, businessscope,
            customer_status, register_id, remark, version))
    conn.commit()
    cursor.close()
    # return


def insert_merberid(c, e):
    cursor = conn.cursor()
    count = cursor.execute(
        "insert  into merberid(id,name,name1) value (NULL ,'%s','%s')" % (c, e))
    conn.commit()
    cursor.close()


def insert_date_no(c, e, r, m):
    cursor = conn.cursor()
    count = cursor.execute(
        "insert  into date_no(id,name,urlTF,url,memberid) value (NULL ,'%s','%s','%s','%s')" % (c, e, r, m))
    conn.commit()
    cursor.close()


def insert_baidu_map(c, a, e, r, m):
    cursor = conn.cursor()
    count = cursor.execute(
        "insert  into baidu_map(id,name,key_addr,key_word,uid,tag,datetimes) value (NULL ,'%s','%s','%s','%s','%s','%s')" % (
            c, a, e, r, m, str(time.strftime('%Y-%m-%d %H:%M:%S'))))
    conn.commit()
    cursor.close()


def update_table(c):
    cursor = conn.cursor()
    count = cursor.execute(
        "UPDATE tett3 SET is_handle='3' where opScope like '%{}%'".format(c))
    print(count)
    conn.commit()
    cursor.close()



def update_dding(e):
    cursor = conn.cursor()
    count = cursor.execute(
        "UPDATE dingding_all_spider SET is_handle='1' where mobile_no='%s'" % e)
    conn.commit()
    cursor.close()


def insert_qwe(n, m, d, p):
    cursor = conn.cursor()
    count = cursor.execute(
        "insert  into qwe(id,name,namegs,address,phone) value (NULL ,'%s','%s','%s','%s')" % (n, m, d, p))
    conn.commit()
    cursor.close()


def insert_all(tables, contacts, phone, mobile_no, key_word, company_name, company_nameCN, source, alibabaId,
               is_overseas,
               account_job, account_jobCN, account_fax, qq, wechart, wechart_remarks, is_wechart, category, industry,
               company_address, account_country, products, company_url, account_province, account_city,
               association_number, pullnew_uid, pullnew_name, conversion_uid, conversion_name, exchange_id, status,
               is_connect, keyword_id, is_handle, create_time, update_time, businessscope,
               customer_status, register_id, remark, version):
    cursor = conn.cursor()
    count = cursor.execute(
        "insert  into %s (id,contacts,phone,mobile_no,key_word,company_name,company_nameCN,source,alibabaId,is_overseas,account_job,account_jobCN,account_fax,qq,wechart,wechart_remarks,is_wechart,category,industry,company_address,account_country,products,company_url,account_province,account_city,association_number,pullnew_uid,pullnew_name,conversion_uid,conversion_name,exchange_id,status,is_connect,keyword_id,is_handle,create_time,update_time,receive_time,end_time,businessscope,customer_status,register_id,remark,version) value (NULL,'%s','%s','%s','%s','%s','%s',%d,'%s',%d,'%s','%s','%s','%s','%s','%s',%d,'%s','%s','%s','%s','%s','%s','%s','%s','%s',%d,'%s',%d,'%s',%d,%d,%d,%d,%d,'%s','%s',NULL ,NULL,'%s',%d,%d,'%s',%d)" % (
            tables, contacts, phone, mobile_no, key_word, company_name, company_nameCN, source, alibabaId, is_overseas,
            account_job, account_jobCN, account_fax, qq, wechart, wechart_remarks, is_wechart, category, industry,
            company_address, account_country, products, company_url, account_province, account_city,
            association_number, pullnew_uid, pullnew_name, conversion_uid, conversion_name, exchange_id, status,
            is_connect, keyword_id, is_handle, create_time, update_time, businessscope,
            customer_status, register_id, remark, version))
    conn.commit()
    cursor.close()


def insert_all_adr(tables, contacts, phone, mobile_no, key_word, company_name, company_nameCN, source, alibabaId,
                   is_overseas,
                   account_job, account_jobCN, account_fax, qq, wechart, wechart_remarks, is_wechart, category,
                   industry,
                   company_address, account_country, products, company_url, account_province, account_city,
                   association_number, pullnew_uid, pullnew_name, conversion_uid, conversion_name, exchange_id, status,
                   is_connect, keyword_id, is_handle, create_time, update_time, businessscope,
                   customer_status, register_id, remark, version, adr):
    cursor = conn.cursor()
    count = cursor.execute(
        "insert  into %s (id,contacts,phone,mobile_no,key_word,company_name,company_nameCN,source,alibabaId,is_overseas,account_job,account_jobCN,account_fax,qq,wechart,wechart_remarks,is_wechart,category,industry,company_address,account_country,products,company_url,account_province,account_city,association_number,pullnew_uid,pullnew_name,conversion_uid,conversion_name,exchange_id,status,is_connect,keyword_id,is_handle,create_time,update_time,receive_time,end_time,businessscope,customer_status,register_id,remark,version,adr) value (NULL,'%s','%s','%s','%s','%s','%s',%d,'%s',%d,'%s','%s','%s','%s','%s','%s',%d,'%s','%s','%s','%s','%s','%s','%s','%s','%s',%d,'%s',%d,'%s',%d,%d,%d,%d,%d,'%s','%s',NULL ,NULL,'%s',%d,%d,'%s',%d,'%s')" % (
            tables, contacts, phone, mobile_no, key_word, company_name, company_nameCN, source, alibabaId, is_overseas,
            account_job, account_jobCN, account_fax, qq, wechart, wechart_remarks, is_wechart, category, industry,
            company_address, account_country, products, company_url, account_province, account_city,
            association_number, pullnew_uid, pullnew_name, conversion_uid, conversion_name, exchange_id, status,
            is_connect, keyword_id, is_handle, create_time, update_time, businessscope,
            customer_status, register_id, remark, version, adr))
    conn.commit()
    cursor.close()
# insert_one1('张宗wqe峰',0,str(time.strftime('%Y-%m-%d %H:%M:%S')),123,'深圳市亦优电子科技有限公司')
# insert_one('张仲宇', '', '18123861546', '卸妆', '深圳市温尔雅化妆用品有限公司', '深圳市温尔雅化妆用品有限公司', 1, '0', 1, '', '', '', '', '', '', 2,
#            '卸妆', '', '地址：中国广东深圳龙岗区龙岗街道平南社区龙岗大道(龙岗段)4001号万汇大厦1105', '', '', '', '', '', '', 0, '', 0, '', 0, 0, 2, 1, 0,
#            str(time.strftime('%Y-%m-%d %H:%M:%S')), str(time.strftime('%Y-%m-%d %H:%M:%S')),
#            '0__亚马逊热卖microfiber 丝绒美妆蛋 网红干湿两用美妆蛋velvet粉扑;1__2020年新款丝绒蛋大牌同款海绵宝宝植绒粉扑组合迷你水滴上妆粉扑;2__迷你桃小屁桃美妆蛋小馒头团子粉扑干湿两用少女系列美妆扑海绵蛋;3__2020新品柠檬蛋糕粉扑芝士粉扑三角蛋糕粉扑黄色瑕疵三角形美妆蛋;4__全网首发新款丝绒蛋大牌同款迷你丝绒蛋植绒粉扑眼影专用迷你水滴;5__纯色橄榄一切粉扑非乳胶美妆蛋2020新款;6__夏季新款芒果粉扑芒果美妆蛋干湿两用非乳胶芒果美妆工具水果粉扑;7__新款咖啡杯垃圾桶美妆蛋环保收纳盒顶部底部滤水设计多功能收纳架;8__粗孔海藻棉洁面扑深层洁面洗脸搓澡多功能泡水大挂绳洗颜扑多色;9__非乳胶红心立体爱心粉扑心形粉扑多色心形粉扑手工爱心粉扑;',
#            0, 0, '', 0)
# print(cc[1][834])
